#include<iostream>
#include<string>
using namespace std;
int main()
{
	int N, n;
	cin >> N;
	while (N--)
	{
		cin >> n;
		int b[5] = { 0 }, min = 99999;
		string a;
		cin >> a;
		int n = a.size();
		for (int i = 0; i < n; i++)
		{
			if (a[i] == 'A')
				b[0]++;
			if (a[i] == 'C')
				b[1]++;
			if (a[i] == 'E')
				b[2]++;
			if (a[i] == 'P')
				b[3]++;
			if (a[i] == 'T')
				b[4]++;
		}
		b[1] = b[1] / 2;
		for (int i = 0; i < 5; i++)
		{
			if (min > b[i])
			{
				min = b[i];
			}
		}
		cout << min << endl;
	}
	system("pause");
	return 0;
}